home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
406_01
/
atoc
/
atoc.doc
< prev
next >
Wrap
Text File
|
1993-11-09
|
5KB
|
148 lines
ATOC - ANSI to K&R C translator
--------------------------------
ATOC is a simple program that converts ANSI-standard C programs to a
form compilable by older K&R compilers. ATOC was written by Mike Rejsa
of Minneapolis, MN, and is placed by the author into the public domain
for general usage at no cost.
DISCLAIMER: THE AUTHOR IS IN NO WAY RESPONSIBLE FOR USE OR MISUSE OF
THIS SOFTWARE, AND TAKES NO RESPONSIBILITY FOR ANY DAMAGE OF ANY KIND
RESULTING FROM USE OF THE SOFTWARE.
A typical ATOC user would be one who is forced and/or perfectly happy
to use an older pre-ANSI compiler with newer ANSI-style source code.
Older compilers frequently run faster and require much less in the way
of machine resources (memory, disk, etc.) than newer ones. Updating can
be tough either because of the expense or because only a limited
computer is available for use.
ATOC is written in K&R style C. If you think about it for a minute,
this makes perfect sense... if you have an ANSI compiler, you don't
need ATOC. I tried hard to make it clean, generic, and portable.
Usage: ATOC [-e] [-i] [-il] [-t] [-v] infile [ outfile ]
Examples of usage:
ATOC file.c (convert and output to display)
ATOC file.c out.c (convert and save)
ATOC -v file.c out.c (convert and save with -v option)
The -e option will cause enumerations to be left alone. Some K&R
compilers support enumerations.
The -i option will cause #include files to be included, converted, and
placed in the output stream. Use ATOC without -i for simple one-time
conversion, like if you have an ANSI program that you want to permanently
convert to K&R style. Use ATOC with -i when you are maintaining ANSI
code and wish to convert an included header 'on-the-fly' each time you
recompile using your K&R compiler.
The -il option is just like -i except that only the local #include
files (those whose name is in " " characters) are included and
converted inline. If an #include files name is in < > characters,
it is left as a normal #include statement. (These are often header
files that come with the compiler, and as such would not be ANSI-C.)
The -t option will cause trigraphs to be left alone. (Note: If an
older compiler supported trigraphs, they may not be ANSI-standard
trigraphs and would therefore pass thru ATOC unchanged anyway.)
The -v option will cause voids to be left alone. Some K&R compilers
support the void data type. (Note: A void used to indicate an empty
function parameter list (e.g. int func( void ) ) is always removed,
even when using the -v option.)
Since ATOC is a line-by-line translator, several parts of ATOC need
a reasonable amount of standard formatting by the programmer. This is
especially important around function declarations and prototypes, where
it is required that the whole thing is contained on one physical line,
and that the closing paren is the last thing on that line except for
a semicolon and/or a comment. Also, enumerations must be completely
contained on one physical line.
The following operations are performed:
ANSI style Translates to:
-------------------------- ---------------------
Prototypes int func( int a, int b ); int func();
(must be on
one line!)
Declarations int func( int a, int b ) int func( a, b )
(must be on { int a;
one line!) int b;
{
Comments // C++ style comment /* comment */
Void void func( void ) int func()
void *p; int *p;
Void using void func( void ) void func()
-v option
There is no special handling for ++p, etc. since you
shouldn't be using pointer math on a void pointer.
Const, signed, const int x; int x;
and volatile signed int y; int y;
removed volatile int z; int z;
Enumerations enum food { apple, pear = 2 }; #define apple 0
(must be on #define pear 2
one line!)
enum food a; int a;
a = pear; a = pear;
Initialized { { /* made static */
automatic int a[] = {1,2}; static int a[] = {1,2};
aggregates
(except typedef'd types)
goto labels label: label: ;
(ANSI requires a statement)
Preprocessor #anystatement removes leading spaces
statements #if defined #ifdef
#if ! defined #ifndef
#elif #else/#if/#endif
ANSI constants \a \007 or \057 (ASCII/EBCDIC)
\v \013 or \013 (ASCII/EBCDIC)
\xnn (hex constant) \nnn (octal constant)
Std macros __STDC__ ignored, left as is
__LINE__ replaced with line number
__FILE__ replaced with "filename"
__DATE__ replaced with "Mmm dd yyyy"
__TIME__ replaced with "hh:mm:ss"
Trigraphs
??< {
(etc.)
The following ANSI items are not handled, but may be covered in
future versions:
New-style function pointers
Unsigned constants (123u 456U)
Adjacent string concatenation
# string literal operator
## token pasting operator
Use and enjoy - long live C!
-mike rejsa, 10/92